use std::io::Write;

use log::info;
use edagent::agent::{Agent, AgentConfig};
use anyhow::{Context, Result};
use simple_logger::SimpleLogger;

async fn result_main() -> Result<()> {
    SimpleLogger::new().init().context("Init logger")?;

    let config = AgentConfig::default();
    let mut agent = Agent::load_config(config)?;
    
    print!("Waht can I do for your?: ");
    std::io::stdout().flush().context("Flush stdout")?;
    let mut user_message = String::new();
    std::io::stdin().read_line(&mut user_message)?;
    
    info!("Processing your request...");
    let answer = agent.run(user_message).await?;
    info!("Request processing completed.");    
    info!("Summary");    
    println!("{}", answer);

    Ok(())
}

#[tokio::main]
async fn main() {
    if let Err(err) = result_main().await {
        eprint!("Err: {}", err);
    }
}